#Python supports the creation of anonymous functions 
#(i.e. functions that are not bound to a name) at runtime, 
#using a construct called "lambda". 
#This is not exactly the same as lambda in functional programming languages, 
#but it is a very powerful concept that's well integrated into Python and 
#is often used in conjunction with typical functional concepts 
#like filter(), map() and reduce(). 

# regular function 
def f (x): 
    return x**2 

print f(8) 

# lambda function 
#Note that the lambda definition does not include a "return" statement 
#It always contains an expression which is returned. 
g = lambda x: x**2 

print g(8) 


# filter, map and reduce with lambda functions 
foo = [3,5,6,9,10,14,18,30,27,30,40] 
print foo 

newFoo = filter(lambda z: z % 3 == 0, foo) 
print newFoo 

newFoo = map(lambda x: x+10, foo) 
print newFoo 

newFoo = reduce(lambda x, y: x + y, foo) 
print newFoo 

aString = "The back of the bus is the best place to be." 
print map(lambda word: len(word), aString.split())

J = [1,3,4,5,6,10,10]
newJ = reduce(lambda x,y: x+y+1, J)
print newJ

